package com.wu.example;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Action1Activity extends BaseActivity {

	private static final String TAG = "Action1Activity";

	private Button btnGoto2 = null;
	private Button btnGoto3 = null;
	private String msg = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.action1);

		msg = this.getIntent().getStringExtra(BrowserIntent.INTENT_FORWARD_TAG);
		TextView txtLable = (TextView) this.findViewById(R.id.txtLabel1);
		txtLable.setText(msg);
		btnGoto2 = (Button) findViewById(R.id.btnGoto2);
		btnGoto2.setText("goto action 2 activity");
		btnGoto3 = (Button)findViewById(R.id.btnGoto3);
		btnGoto3.setText("goto action 2 activity from main ");
		
		btnGoto2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 
				Intent i = new Intent(Action1Activity.this,
						Action2Activity.class);
				i.putExtra(BrowserIntent.INTENT_FORWARD_TAG, msg
						+ "\nclick goto 2 button goto 2 Action2Activity.class");
				startActivityForResult(i, BrowserIntent.REQUEST_TO_2);
			}
		});
		btnGoto3.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent();
				i.putExtra(BrowserIntent.INTENT_FORWARD_TAG, msg + "\nclick goto 2 button goto 2 Action2Activity.class from main Activity");
				i.putExtra(BrowserIntent.RESULT_TO_CLASS, Action2Activity.class.getName());
				setResult(BrowserIntent.RESULT_FROM_2,i);
				finish();
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		Log.d(TAG, "onActivityResult[requestCode]" + requestCode
				+ "[resultCode]" + resultCode);
//		super.onActivityResult(requestCode, resultCode, data);
		setResult(resultCode, data);
		finish();
	}

}
